<?php

require_once 'DB.class.php';

class Issue {


	public $o_id;
	public $o_date;
	public $o_status;
	public $o_codeA;
	public $o_codeB;
	public $o_codeC;
	public $o_codeD;
	
	
	//Constructor is called whenever a new object is created.
	//Takes an associative array with the DB row as an argument.
	function __construct($data) {
		$this->o_date = (isset($data['o_date'])) ? $data['o_date'] : "";
		$this->o_status = (isset($data['o_status'])) ? $data['o_status'] : "";
		$this->o_codeA = (isset($data['o_codeA'])) ? $data['o_codeA'] : "";
		$this->o_codeB = (isset($data['o_codeB'])) ? $data['o_codeB'] : "";
		$this->o_codeC = (isset($data['o_codeC'])) ? $data['o_codeC'] : "";
		$this->o_codeD = (isset($data['o_codeD'])) ? $data['o_codeD'] : "";
	}

	public function save($isNewData = false) {
		//create a new database object.
		$db = new DB();

		//if the user is already registered and we're
		//just updating their info.
		if(!$isNewData) {
			//set the data array
			$data = array(
				"o_date" => "'$this->o_date'",
				"o_status" => "'$this->o_status'",
				"o_codeA" => "'$this->o_codeA'",
				"o_codeB" => "'$this->o_codeB'",
				"o_codeC" => "'$this->o_codeC'",
				"o_codeD" => "'$this->o_codeD'",
			);

			//update the row in the database
			$db->update($data, 'od', 'o_id = '.$this->o_id);
		}else {
		//if the user is being registered for the first time.
			$data = array(
				"o_date" => "'$this->o_date'",
				"o_status" => "'$this->o_status'",
				"o_codeA" => "'$this->o_codeA'",
				"o_codeB" => "'$this->o_codeB'",
				"o_codeC" => "'$this->o_codeC'",
				"o_codeD" => "'$this->o_codeD'",
			);

			$this->o_id = $db->insert($data, 'od');
		}
		return true;
	}
	
	public function remove($id) {
			mysql_query("DELETE FROM  `od` WHERE  `o_id` =  '$id'");
	}

}

?>